#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main()
{
    int t = 0;
    cin >> t;
    vector<int> v;
    while (t--)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        for (int i = x;i <= y;i++)
        {
            if (i <= 1)
            {
                continue;
            }
            int t = sqrt(i) + 1;
            int a = 1;
            for (int j = 2;j < t;j++)
            {
                if (i % j == 0)
                {
                    a = 0;
                    break;
                }
            }
            if (a == 1)
            {
                v.push_back(i);
            }
        }
        int cur = v[0];
        int count = 0;
        for (int left = 0, right = 1;right < v.size();right++)
        {

            int in = v[right];
            cur &= in;
            if (cur == 0)
            {
                count++;
                left = right;
                cur = v[right];
            }
        }
        int n = v.size();
        printf("%d %d\n", n, count);
        v.clear();
    }
    return 0;
}